package com.banzhi.shop.activity;

import android.content.Intent;
import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.banzhi.shop.R;
import com.banzhi.shop.adapter.HomeFrgAda;
import com.banzhi.shop.adapter.MyCollegeAdapter;
import com.banzhi.shop.base.BaseActivity;
import com.banzhi.shop.fragment.OrderFrg;
import com.banzhi.shop.fragment.Shouyi_DaifaFragment;
import com.banzhi.shop.fragment.Shouyi_YifaFragment;
import com.banzhi.shop.fragment.VIPOrderFragment;
import com.banzhi.shop.fragment.VideoOrderFragment;
import com.banzhi.shop.utils.TabLayoutUtil;
import com.banzhi.shop.utils.ToastUtils;
import com.banzhi.shop.utils.Translucent;
import com.banzhi.shop.view.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

public class OrderManagementActivity2 extends BaseActivity implements View.OnClickListener {

    private ImageView ivBackOrder;
    private TextView tvShopOrder;
 //   private TextView tvCollegeOrder;
    private ImageView ivOrderSousuo;
    private LinearLayout llShopOrder;
    private NoScrollViewPager vpShopOrder;
 //   private LinearLayout llCollegeOrder;
 //   private NoScrollViewPager vpCollegeOrder;
 //   private TabLayout tabsCollegeOrder;
    private TabLayout tabsShopOrder;

    private int type;

    private List<String> mTitle = new ArrayList<String>();
    private List<Fragment> mFragment = new ArrayList<Fragment>();
    private ImageView ivOrderSousuo2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_management2);
        Translucent.setTranslucent(this);

        initView();
        initeListeners();
        Intent intent = getIntent();
        type = intent.getIntExtra("type", 0);
        if (type == 1) {
            tvShopOrder.setText("今日订单");
        }

    }

    protected void onStart() {
        super.onStart();
         tabsShopOrder.post(new Runnable() {
            @Override
            public void run() {
                TabLayoutUtil.setIndicator( tabsShopOrder, 6, 6);
            }
        });
    }

    private void initView() {
        ivBackOrder = (ImageView) findViewById(R.id.iv_back_order);
        tvShopOrder = (TextView) findViewById(R.id.tv_shop_order);

        ivOrderSousuo = (ImageView) findViewById(R.id.iv_order_sousuo);
        ivOrderSousuo2 = (ImageView) findViewById(R.id.iv_order_sousuo2);

        llShopOrder = (LinearLayout) findViewById(R.id.ll_shop_order);
        vpShopOrder = (NoScrollViewPager) findViewById(R.id.vp_shop_order);
        tabsShopOrder = (TabLayout) findViewById(R.id.tabs_shop_order);
/*
        tabsCollegeOrder = (TabLayout) findViewById(R.id.tabs_college_order);
        tvCollegeOrder = (TextView) findViewById(R.id.tv_college_order);
        vpCollegeOrder = (NoScrollViewPager) findViewById(R.id.vp_college_order);
        llCollegeOrder = (LinearLayout) findViewById(R.id.ll_college_order);*/
        vpShopOrder.setOffscreenPageLimit(5);//同时加载旁边的fragment的页面布局
        //店铺订单
        List<Fragment> fras = new ArrayList<>();
        OrderFrg frg1 = new OrderFrg().newInstance("-1");//全部订单
        OrderFrg frg2 = new OrderFrg().newInstance("0");//待付款
        OrderFrg frg3 = new OrderFrg().newInstance("1");//待发货
        OrderFrg frg4 = new OrderFrg().newInstance("2");//待收货
        OrderFrg frg5 = new OrderFrg().newInstance("3");//已完成
        OrderFrg frg6 = new OrderFrg().newInstance("-2");//已取消
        fras.add(frg1);
        fras.add(frg2);
        fras.add(frg3);
        fras.add(frg4);
        fras.add(frg5);
        fras.add(frg6);
        List<String> list = new ArrayList<>();
        list.add("全部");
        list.add("待付款");
        list.add("待发货");
        list.add("待收货");
        list.add("已完成");
        list.add("已取消");
        HomeFrgAda homeFrgAda = new HomeFrgAda(this.getSupportFragmentManager(), fras, list);
        vpShopOrder.setAdapter(homeFrgAda);
        tabsShopOrder.setupWithViewPager(vpShopOrder);
        //学院订单

    }

    private void initeListeners() {
        ivBackOrder.setOnClickListener(this);
        tvShopOrder.setOnClickListener(this);

        ivOrderSousuo.setOnClickListener(this);
        ivOrderSousuo2.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back_order:
                finish();
                break;

            case R.id.iv_order_sousuo:

                Intent intent = new Intent(this, FindOrderActivity.class);
                startActivity(intent);
                break;
            case R.id.iv_order_sousuo2:

                Intent intent2 = new Intent(this, FindOrderActivity2.class);
                startActivity(intent2);
                break;

        }

    }

    public int getType() {
        return type;
    }
}
